package com.tao.plan.common;


import com.tao.plan.common.constant.StatusCodeConst;

import java.util.HashMap;
import java.util.Map;

public class R extends HashMap<String, Object> {

	public static R build(){
		return new R();
	}
	public static R build(Map<String,Object> map){
		R res = new R();
		map.keySet().forEach(k->{
			res.put(k,map.get(k));
		});
		return res;
	}
	public R put(String key, Object val){
		super.put(key,val);
		return this;
	}
	public R success(){
		this.put("msg","成功");
		this.put("code", StatusCodeConst.SUCCESS);
		return this;
	}
	public R fail(){
		this.put("msg","失败");
		this.put("code",StatusCodeConst.FAIL);
		return this;
	}
	public R fail(String msg){
		this.put("msg",msg);
		this.put("code",StatusCodeConst.FAIL);
		return this;
	}
	public R fail(Integer code, String msg){
		this.put("msg",msg);
		this.put("code",code);
		return this;
	}
}
